<?php

	require_once dirname(__FILE__) . '/../../pdo/ProfessorPDO.php';
	require_once dirname(__FILE__) . '/../../model/Professor.php';
	
	class ProfessorService
	{
		
		private $pdo = null;
		
		public function __construct() {
			$this->pdo = new ProfessorPDO();
		}
		
		public function inserirProfessor($professor)
		{
			$this->pdo->inserir($professor);
		}
		
		public function alterarProfessor($professor)
		{
			$this->pdo->alterar($professor);
		}
		
		public function deletarProfessor($id)
		{
			$this->pdo->deletar($id);
		}
		
		public function pesquisarProfessor($busca)
		{
			$lista = Array();
			$consulta = $this->pdo->pesquisar($busca);
			foreach ($consulta as $i => $value) {
				$professor = new Professor();
				$professor->id = $consulta[$i]['id'];
				$professor->nome = $consulta[$i]['nome'];
				$professor->email = $consulta[$i]['email'];
				$professor->cpf = $consulta[$i]['cpf'];
				$professor->usuario->id = $consulta[$i]['usuario_id'];
				$professor->usuario->username = $consulta[$i]['username'];
				$professor->usuario->password = $consulta[$i]['password'];
				$professor->usuario->perfil = $consulta[$i]['perfil'];
				$lista[$i] = $professor;
			}
			return $lista;
		}
		
		public function listarProfessores()
		{
			$lista = Array();
			$consulta = $this->pdo->listar();		
			foreach ($consulta as $i => $value) {
				$professor = new Professor();
				$professor->id = $consulta[$i]['id'];
				$professor->nome = $consulta[$i]['nome'];
				$professor->email = $consulta[$i]['email'];
				$professor->cpf = $consulta[$i]['cpf'];
				$professor->usuario->id = $consulta[$i]['usuario_id'];
				$professor->usuario->username = $consulta[$i]['username'];
				$professor->usuario->password = $consulta[$i]['password'];
				$professor->usuario->perfil = $consulta[$i]['perfil'];
				$lista[$i] = $professor;
			}
			return $lista;
		}
	}
?>